package com.qinglei.recoup.longconn.service.impl;

import com.qinglei.recoup.longconn.enums.ProtocolVersionEnum;
import com.qinglei.recoup.longconn.service.IotMessageHandleV7Service;
import com.qinglei.recoup.longconn.service.IotMessageStrategyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 物联网消息处理协议V7实现
 *
 * @author yujunwei
 * @datetime 2022-03-02 17:14
 */
@Service
@Slf4j
public class IotMessageStrategyV7ServiceImpl implements IotMessageStrategyService {

    @Autowired
    private IotMessageHandleV7Service iotMessageHandleV7Service;

    @Override
    public String protocolVersion() {
        return ProtocolVersionEnum.V7.getVersion();
    }

    @Override
    public void handleMethod(Map<String, Object> map) {

        Object message = iotMessageHandleV7Service.parseIotMessage(map);
        iotMessageHandleV7Service.handleIotMessage(message);
        if (message != null) {
            HashMap<String, Object> messageMap = (HashMap<String, Object>) message;
            log.info("into ProtocolVersion 7 handle -> sn:{}, frameNo:{}", messageMap.get("SN"), messageMap.get("FRAME"));
        }
    }
}
